﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Net.Mail;
using System.Data.SqlClient;

namespace WebBase
{
    public class Comm
    {

        #region 去掉HTML标签
        ///   <summary>
        ///   去除HTML标记
        ///   </summary>
        ///   <param   name="NoHTML">包括HTML的源码   </param>
        ///   <returns>已经去除后的文字</returns>
        public static string NoHTML(string Htmlstring)
        {
            //删除脚本
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "",
              RegexOptions.IgnoreCase);
            //删除HTML
            Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9",
              RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "",
              RegexOptions.IgnoreCase);

            Htmlstring.Replace("<", "");
            Htmlstring.Replace(">", "");
            Htmlstring.Replace("\r\n", "");
            Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

            return Htmlstring;
        }
        public static string ParseTags(string HTMLStr)
        {
            return System.Text.RegularExpressions.Regex.Replace(HTMLStr, "<[^>]*>", "");
        }
        #endregion

        #region 验证数值
        /// <summary>
        ///  验证数值
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsNumeric(string str)
        {
            System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
            if (string.IsNullOrEmpty(str))
                return false;
            else
                return reg1.IsMatch(str);
        }
        #endregion

        #region 数值格式化
        public static string NumberTrim(object objSrc)
        {
            string strSrc = Convert.ToString(objSrc);
            if (strSrc.IndexOf('.') != -1)
                strSrc = strSrc.TrimEnd('0');
            if (strSrc.EndsWith("."))
                strSrc = strSrc.TrimEnd('.');
            return strSrc;
        }
        public static string NumberFormat(object objSrc)
        {
            return NumberFormat(objSrc, 0, 0);
        }
        public static string NumberFormat(object objSrc, int iLength)
        {
            return NumberFormat(objSrc, iLength, 0, false);
        }
        public static string NumberFormat(object objSrc, int iLength, int format)
        {
            return NumberFormat(objSrc, iLength, format, true);
        }
        public static string NumberFormat(object objSrc, int iLength, int format, bool IfZero)
        {
            string strResult = string.Empty;

            string strObject = Convert.ToString(objSrc).Trim();
            if (string.IsNullOrEmpty(strObject))
                objSrc = "0";

            switch (format)
            {
                case 0:
                    if (Math.Round(Convert.ToDecimal(objSrc), iLength) == 0)
                    {
                        strResult = "0";
                    }
                    else if (Math.Round(Convert.ToDecimal(objSrc), iLength) < 100)
                    {
                        if (Math.Round(Convert.ToDecimal(objSrc), iLength) < 0)
                        {
                            strResult = (Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength)) < 1) ? Convert.ToString(Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength))) : Convert.ToString(Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength))).TrimStart('0');
                            strResult = "-" + strResult;
                        }
                        else
                        {
                            strResult = (Convert.ToDecimal(objSrc) < 1) ? Convert.ToString(Math.Round(Convert.ToDecimal(objSrc), iLength)) : Convert.ToString(Math.Round(Convert.ToDecimal(objSrc), iLength)).TrimStart('0');
                        }
                    }
                    else
                    {
                        strResult = Convert.ToString(Math.Round(Convert.ToDecimal(objSrc), iLength));
                    }
                    break;
                default:
                    if (Math.Round(Convert.ToDecimal(objSrc), iLength) == 0)
                    {
                        strResult = "0";
                    }
                    else if (Math.Round(Convert.ToDecimal(objSrc), iLength) < 100)
                    {
                        if (Math.Round(Convert.ToDecimal(objSrc), iLength) < 0)
                        {
                            strResult = (Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength)) < 1) ? string.Format("{0:N}", Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength))) : string.Format("{0:N}", Math.Abs(Math.Round(Convert.ToDecimal(objSrc), iLength))).TrimStart('0');
                            strResult = "-" + strResult;
                        }
                        else
                        {
                            strResult = (Convert.ToDecimal(objSrc) < 1) ? string.Format("{0:N}", Math.Round(Convert.ToDecimal(objSrc), iLength)) : string.Format("{0:N}", Math.Round(Convert.ToDecimal(objSrc), iLength)).TrimStart('0');
                        }
                    }
                    else
                    {
                        strResult = string.Format("{0:N}", Math.Round(Convert.ToDecimal(objSrc), iLength));
                        //strResult = Math.Round(Convert.ToDecimal(objSrc), iLength).ToString("N");
                    }
                    break;
            }
            if (strResult.IndexOf('.') != -1 && IfZero == false)
                strResult = strResult.TrimEnd('0');
            if (strResult.EndsWith("."))
                strResult = strResult.TrimEnd('.');
            return strResult;
        }
        #endregion

        #region UTF8Code转字符
        /// <summary>
        /// UTF8Code转字符
        /// </summary>
        /// <param name="strUTF8Code"></param>
        /// <returns></returns>
        public static string UTF2String(string strUTF8Code)
        {
            string strResult = string.Empty;
            if (!string.IsNullOrEmpty(strUTF8Code))
            {
                System.Text.UTF8Encoding ut = new UTF8Encoding();
                strUTF8Code = strUTF8Code.TrimEnd(',');
                string[] UTF8CodeArr = strUTF8Code.Split(',');
                Byte[] bUTF8Code = new Byte[UTF8CodeArr.Length];
                for (int i = 0; i < UTF8CodeArr.Length; i++)
                {
                    bUTF8Code[i] = Convert.ToByte(Convert.ToInt32(UTF8CodeArr[i]));
                }
                strResult = ut.GetString(bUTF8Code);
            }
            return strResult;
        }
        #endregion

        #region 正则防SQL驻入
        /// <summary>
        /// 正则防SQL驻入
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static bool CheckParams(params object[] args)
        {
            bool bResult = false;
            //string[] Lawlesses ={ "select", "exec", "insert", "delete", "update", "count", "master", "truncate", "declare", "shell" };
            //if (Lawlesses == null || Lawlesses.Length <= 0) return true;
            //string str_Regex = ".*[";
            //for (int i = 0; i < Lawlesses.Length - 1; i++)
            //    str_Regex += Lawlesses + "|";
            //str_Regex += Lawlesses[Lawlesses.Length - 1] + "].*";
            string str_Regex = @"(select|exec|insert|delete|update|count|master|truncate|declare|shell|drop|alter|use)+?\b|.*[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\'].*";
            foreach (object arg in args)
            {
                if (arg is string)//如果是字符串,直接检查 
                {
                    MatchCollection mc = Regex.Matches(arg.ToString(), str_Regex, RegexOptions.IgnoreCase);
                    if (mc.Count > 0)
                        return false;
                }
                else if (arg is ICollection)//如果是一个集合,则检查集合内元素是否字符串,是字符串,就进行检查 
                {
                    foreach (object obj in (ICollection)arg)
                    {
                        if (obj is string)
                        {
                            if (Regex.Matches(obj.ToString(), str_Regex).Count > 0)
                                return false;
                        }
                    }
                }
            }
            return true;
        }
        #endregion

        #region 用户操作系统
        /// <summary>
        /// 用户操作系统
        /// </summary>
        public static string GetOS
        {
            get
            {
                string strOS = "unknow";
                try
                {
                    HttpBrowserCapabilities bc = System.Web.HttpContext.Current.Request.Browser;
                    string OSName = bc.Platform;
                    switch (bc.Platform)
                    {
                        case "Win98":
                            OSName = "Windows98";
                            break;
                        case "WinNT 5.1":
                        case "WinXP":
                            OSName = "Windows XP";
                            break;
                        case "WinNT 5.0":
                            OSName = "Win2000";
                            break;
                        case "WinNT":
                            OSName = "Win2003";
                            break;
                        default:
                            OSName = bc.Platform;
                            break;
                    }
                    strOS = OSName;
                }
                catch
                { }
                return strOS;
            }
        }
        #endregion

        #region 获取用户浏览器
        /// <summary>
        /// 获取用户浏览器
        /// </summary>
        public static string GetUserBrowser
        {
            get
            {
                string strUserBrowser = "unknow";
                try
                {
                    strUserBrowser = System.Web.HttpContext.Current.Request.Browser.Browser + System.Web.HttpContext.Current.Request.Browser.Version;
                }
                catch
                { }
                return strUserBrowser;
            }
        }
        #endregion

        #region 过滤HTML
        /// <summary>
        /// 过滤HTML
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static string HTMLDecode(string html)
        {
            html = HttpUtility.HtmlDecode(html);
            System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html = regex1.Replace(html, ""); //过滤<script></script>标记 
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 
            html = regex4.Replace(html, ""); //过滤iframe 
            html = regex5.Replace(html, ""); //过滤frameset 
            html = regex6.Replace(html, ""); //过滤frameset 
            html = regex7.Replace(html, ""); //过滤frameset 
            html = regex8.Replace(html, ""); //过滤frameset 
            html = regex9.Replace(html, "");
            html = html.Replace(" ", "");
            html = html.Replace("</strong>", "");
            html = html.Replace("<strong>", "");
            return html;
        }
        public static string HTMLDecode(string html, int iLength)
        {
            string strHtml = HTMLDecode(html);
            strHtml = strHtml.Length >= iLength ? strHtml.Substring(0, iLength) + "..." : strHtml;
            return strHtml;
        }
        #endregion

        #region 获取Grid选中的ID项
        /// <summary>
        /// 获取Grid选中的ID项
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public static List<int> GetGridSeleteRowId(FineUI.Grid g)
        {
            int iTempResult = 0;
            List<int> lstResult = null;
            lstResult = new List<int>();
            for (int i = 0; i < g.SelectedRowIndexArray.Length; i++)
            {
                int rowIndex = g.SelectedRowIndexArray[i];

                // 如果是内存分页，所有分页的数据都存在，rowIndex 就是在全部数据中的顺序，而不是当前页的顺序
                if (g.AllowPaging && !g.IsDatabasePaging)
                {
                    rowIndex = g.PageIndex * g.PageSize + rowIndex;
                }
                object[] dataKeys = g.DataKeys[rowIndex];
                for (int j = 0; j < dataKeys.Length; j++)
                {
                    int.TryParse(Convert.ToString(dataKeys[j]), out iTempResult);
                    lstResult.Add(iTempResult);
                }
            }
            return lstResult;
        }
        #endregion

        #region 获取数据库分页
        /// <summary>
        /// 获取数据库分页
        /// </summary>
        /// <param name="strCondition"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strOrderFields"></param>
        /// <param name="OrderType"></param>
        /// <param name="pageCount"></param>
        /// <param name="Counts"></param>
        /// <returns></returns>
        public static DataSet SelectByPage(string strTableName, string strFieldName, string strKeyId, string strCondition, int pageSize, int pageIndex, string strOrderFields, int OrderType, out int pageCount, out int Counts)
        {
            IDataParameter[] parameters = new OleDbParameter[10];
            parameters[0] = new OleDbParameter("@TableName", OleDbType.VarChar, 200);//  
            parameters[1] = new OleDbParameter("@SelectFields", OleDbType.VarChar, 1000);
            parameters[2] = new OleDbParameter("@PageSize", OleDbType.Integer);//
            parameters[3] = new OleDbParameter("@CurrentPage", OleDbType.Integer);//当前页码
            parameters[4] = new OleDbParameter("@TotalPage", OleDbType.Integer);//
            parameters[5] = new OleDbParameter("@RowsCount", OleDbType.Integer);//
            parameters[6] = new OleDbParameter("@OrderField", OleDbType.VarChar, 200);//-排序字段,如果是多个字段，除最后一个字段外，后面都要加排序条件（asc/desc），不包含order by,最后一个排序字段不用加排序条件   
            parameters[7] = new OleDbParameter("@OrderType", OleDbType.TinyInt);//排序访求，0：升序，1：降序
            parameters[8] = new OleDbParameter("@strWhere", OleDbType.VarChar, 1000);// 查询条件，不要where
            parameters[9] = new OleDbParameter("@IdField", OleDbType.VarChar, 150);//主表的主键

            parameters[0].Value = strTableName;
            parameters[1].Value = strFieldName;
            parameters[2].Value = pageSize;
            parameters[3].Value = pageIndex;
            parameters[6].Value = strOrderFields;
            parameters[7].Value = OrderType;
            parameters[8].Value = strCondition;
            parameters[9].Value = strKeyId;
            //parameters[10].Value = 0;

            parameters[4].Direction = ParameterDirection.Output;
            parameters[5].Direction = ParameterDirection.Output;

            DataSet ds = SqlHelper.RunProcedure("proc_ListPageInt", parameters, strTableName);
            pageCount = Convert.ToInt32(parameters[4].Value);
            Counts = Convert.ToInt32(parameters[5].Value);

            return ds;
        }
        /// <summary>
        /// 获取数据库分页
        /// </summary>
        /// <param name="strTableName">数据表名</param>
        /// <param name="strFieldName">显示字段（所有 *，如有多个则用“逗号”隔开）</param>
        /// <param name="strQuery">查询条件</param>
        /// <param name="strFieldSort">排序字段</param>
        /// <param name="iKeyId">主键</param>
        /// <param name="iDist"> 是否添加查询字段的 DISTINCT 默认0不添加/1添加</param>
        /// <param name="iSort">排序升（降） 即0-升 1-降</param>
        /// <param name="iPageSize">每页显示记录数</param>
        /// <param name="iPageIndex">当前页面索引</param>
        /// <param name="iPageCount">返回总页面数</param>
        /// <param name="iRecordCount">返回总记录数</param>
        /// <returns></returns>
        public static DataSet SelectByPage(string strTableName, string strFieldName, string strQuery, string strFieldSort, string strKeyId, int iDist, int iSort, int iPageSize, int iPageIndex, out int iPageCount, out int iRecordCount)
        {
            IDataParameter[] parameters = new OleDbParameter[11];
            parameters[0] = new OleDbParameter("@tblName", OleDbType.VarWChar, 1000);//表名 
            parameters[1] = new OleDbParameter("@ID", OleDbType.VarWChar, 150);//主键
            parameters[2] = new OleDbParameter("@page", OleDbType.Integer);//当前分页索引
            parameters[3] = new OleDbParameter("@pageSize", OleDbType.Integer);//每页显示记录数
            parameters[4] = new OleDbParameter("@fldName", OleDbType.VarWChar, 500);//显示字段名
            parameters[5] = new OleDbParameter("@fldSort", OleDbType.VarWChar, 200);//排序字段列表或条件
            parameters[6] = new OleDbParameter("@Sort", OleDbType.Integer);//排序方法，0为升序，1为降序
            parameters[7] = new OleDbParameter("@strCondition", OleDbType.VarWChar, 1000);//查询条件,不需where,如："and a=1 and b=2"
            parameters[8] = new OleDbParameter("@Dist", OleDbType.Integer);// 是否添加查询字段的 DISTINCT 默认0不添加/1添加
            parameters[9] = new OleDbParameter("@Counts", OleDbType.Integer);//查询到的记录数
            parameters[10] = new OleDbParameter("@pageCount", OleDbType.Integer);//查询结果分页后的总页数

            parameters[0].Value = strTableName;
            parameters[1].Value = strKeyId;
            parameters[2].Value = iPageIndex;
            parameters[3].Value = iPageSize;
            parameters[4].Value = strFieldName;
            parameters[5].Value = strFieldSort;
            parameters[6].Value = iSort;
            parameters[7].Value = strQuery;
            parameters[8].Value = iDist;
            parameters[9].Direction = ParameterDirection.Output;
            parameters[10].Direction = ParameterDirection.Output;

            DataSet ds = SqlHelper.RunProcedure("getPagerTopMAX", parameters, strTableName);
            iRecordCount = Convert.ToInt32(parameters[9].Value);
            iPageCount = Convert.ToInt32(parameters[10].Value);
            return ds;
        }
        #endregion

        #region 获取图片高、宽值
        /// <summary>
        /// 获取图片高、宽值
        /// </summary>
        /// <param name="strPicPath">图片目录</param>
        /// <param name="strPhyPath">站点物理路径</param>
        /// <param name="iWidth">取回宽度</param>
        /// <param name="iHeight">取回高度</param>
        /// <returns></returns>
        public static string GetPicWH(string strPicPath, string strPhyPath, ref int iWidth, ref int iHeight)
        {
            string strResult = string.Empty;
            try
            {
                if (strPhyPath.EndsWith(@"\"))
                    strPhyPath = strPhyPath.Substring(0, strPhyPath.Length - 1);
                strResult = strPhyPath + strPicPath.Replace('/', '\\');
                System.Drawing.Image img = System.Drawing.Image.FromFile(strResult);
                double _width = img.Size.Width;
                double _height = img.Size.Height;
                double _zoom_factor = _width / iWidth;
                if (_height / iHeight > _zoom_factor) _zoom_factor = _height / iHeight;
                if (_zoom_factor > 1)
                {
                    iWidth = Convert.ToInt32(_width / _zoom_factor);
                    iHeight = Convert.ToInt32(_height / _zoom_factor);
                }
            }
            catch { }
            return strResult;
        }
        #endregion

        #region 上传图片
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileUpload">上传控件名</param>
        /// <param name="strPhyPath">物理路径</param>
        /// <param name="strVirPath">虚拟路径</param>
        /// <param name="strFileExt">文件扩展名</param>
        /// <param name="strResult">返回操作结果信息</param>
        /// <returns>返回操作结果</returns>
        public static string GetFilePath(FineUI.FileUpload fileUpload, string strPhyPath, string strVirPath, string strFileExt, ref string strResult)
        {
            return GetFilePath(fileUpload, strPhyPath, strVirPath, false, 0, strFileExt, ref strResult);
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileUpload"></param>
        /// <param name="strPhyPath"></param>
        /// <param name="strVirPath"></param>
        /// <param name="HadSmallImg"></param>
        /// <param name="dZoomValue"></param>
        /// <param name="strFileExt"></param>
        /// <param name="strResult"></param>
        /// <returns></returns>
        public static string GetFilePath(FineUI.FileUpload fileUpload, string strPhyPath, string strVirPath, bool HadSmallImg, double dZoomValue, string strFileExt, ref string strResult)
        {
            return GetFilePath(fileUpload, strPhyPath, strVirPath, HadSmallImg, false, dZoomValue, strFileExt, ref strResult);
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileUpload"></param>
        /// <param name="ClassId"></param>
        /// <param name="HadSmallImg"></param>
        /// <param name="strFileExt"></param>
        /// <param name="strResult"></param>
        /// <returns></returns>
        public static string GetFilePath(FineUI.FileUpload fileUpload, string strPhyPath, string strVirPath, bool HadSmallImg, bool HadBigImg, double dZoomValue, string strFileExt, ref string strResult)
        {
            string fileName = string.Empty;
            string smallFileName = string.Empty, bigFileName = string.Empty;
            string serverpath1 = string.Empty, serverpath2 = string.Empty, serverpath0 = string.Empty;
            if (fileUpload.HasFile)
            {
                fileName = fileUpload.ShortFileName;
                fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;

                smallFileName = "small_" + fileName;
                bigFileName = "big_" + fileName;

                serverpath2 = strPhyPath + smallFileName;
                serverpath1 = strPhyPath + fileName;
                serverpath0 = strPhyPath + bigFileName;

                //检查目录是否存在，不存在则创建
                if (!Directory.Exists(strPhyPath))
                    Directory.CreateDirectory(strPhyPath);
                //文件保存
                fileUpload.SaveAs(serverpath0);
                fileName = strVirPath + fileName;

                ImageThumbnail img;
                if (HadBigImg)
                {
                    //保存大图
                    img = new ImageThumbnail(serverpath0);
                    img.ReducedImage(0.6, serverpath1);
                }
                else
                {
                    fileName = strVirPath + bigFileName;
                }
                if (HadSmallImg)
                {
                    img = new ImageThumbnail(serverpath0);
                    img.ReducedImage(dZoomValue, serverpath2);
                }
                strResult = "图片上传成功";
            }
            return fileName;
        }
        #endregion

        #region 发送电子邮件
        public static void SendMailLocalhost(StringBuilder sbMailContent, string strMailSubject, string strRecivedMail, string SMTPHost, int SMTPPort, string SMTPUser, string SMTPUserPwd, string strShowEmail, string strShowName, bool IsHtml, ref string strResult)
        {
            List<MailAddress> lstMail = new List<MailAddress>();
            lstMail.Add(new MailAddress(strRecivedMail));
            SendMailLocalhost(sbMailContent, strMailSubject, lstMail, SMTPHost, SMTPPort, SMTPUser, SMTPUserPwd, strShowEmail, strShowName, IsHtml, ref strResult);
        }
        /// <summary>
        /// 发送电子邮件
        /// </summary>
        /// <param name="sbMailContent">邮件内容</param>
        /// <param name="strMailSubject">主题</param>
        /// <param name="strRecivedMail">收件邮箱</param>
        /// <param name="SMTPHost">SMTP地址</param>
        /// <param name="SMTPPort">SMTP端口</param>
        /// <param name="SMTPUser">邮件帐户</param>
        /// <param name="SMTPUserPwd">邮件密码</param>
        /// <param name="strShowEmail">显示发件人邮箱</param>
        /// <param name="strShowName">显示发件人</param>
        /// <param name="strResult">返回发信结果</param>
        public static void SendMailLocalhost(StringBuilder sbMailContent,string strMailSubject,List<MailAddress> lstMail,string SMTPHost,int SMTPPort,string SMTPUser,string SMTPUserPwd,string strShowEmail,string strShowName,bool IsHtml,ref string strResult)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            foreach (MailAddress ma in lstMail)
                msg.To.Add(ma);
            msg.From = new MailAddress(strShowEmail, strShowName, System.Text.Encoding.UTF8);
            /* 上面3个参数分别是发件人地址（可以随便写），发件人姓名，编码*/
            msg.Subject = strMailSubject;//邮件标题 
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
            msg.Body = sbMailContent.ToString();//邮件内容 
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
            msg.IsBodyHtml = IsHtml;//是否是HTML邮件 
            msg.Priority = MailPriority.High;//邮件优先级 

            SmtpClient client = new SmtpClient(SMTPHost);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPUserPwd);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                client.Send(msg);
                strResult = "发送成功！";
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                strResult = ex.Message;
            }
        }
        #endregion

        #region 获取订单号
        /// <summary>
        /// 获取订单号
        /// </summary>
        /// <param name="OrderName">订单区分位（为两位英文字母）</param>
        /// <returns></returns>
        public static string GetOrderNo(string OrderName)
        {
            return OrderName + DateTime.Now.Ticks.ToString();
        }
        #endregion

        #region 生成随机订单号
        /// <summary>
        /// 生成随机订单号
        /// </summary>
        /// <param name="sQZ">前缀</param>
        /// <returns>订单号</returns>
        public static string GetOrderSN(string sQZ)
        {
            string strResult = string.Empty;
            IDataParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@SNF", SqlDbType.VarChar, 50);
            parameters[0].Value = sQZ;

            DataSet ds = SqlHelper.RunProcedure("GetOrderSN", parameters, "wyOrderSN");
            return Convert.ToString(ds.Tables[0].Rows[0][0]);
        }
        #endregion

        #region 系统自动生成密码
        /// <summary>
        /// 系统自动生成密码
        /// </summary>
        /// <param name="iLength"></param>
        /// <returns></returns>
        public static string GetMix(int iLength)
        {
            string strResult = string.Empty;
            strResult = GetRnd(iLength, true, true, true, false, "Wysx");
            return strResult;
        }
        ///<summary>
        ///生成随机字符串
        ///</summary>
        ///<param name="length">目标字符串的长度</param>
        ///<param name="useNum">是否包含数字，1=包含，默认为包含</param>
        ///<param name="useLow">是否包含小写字母，1=包含，默认为包含</param>
        ///<param name="useUpp">是否包含大写字母，1=包含，默认为包含</param>
        ///<param name="useSpe">是否包含特殊字符，1=包含，默认为不包含</param>
        ///<param name="custom">要包含的自定义字符，直接输入要包含的字符列表</param>
        ///<returns>指定长度的随机字符串</returns>
        public static string GetRnd(int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom)
        {
            byte[] b = new byte[4];
            new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
            Random r = new Random(BitConverter.ToInt32(b, 0));
            string s = null, str = custom;
            if (useNum == true) { str += "0123456789"; }
            if (useLow == true) { str += "abcdefghijklmnopqrstuvwxyz"; }
            if (useUpp == true) { str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
            if (useSpe == true) { str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
            for (int i = 0; i < length; i++)
            {
                s += str.Substring(r.Next(0, str.Length - 1), 1);
            }
            return s;
        }
        #endregion
    }
}
